import dao.TemperatureSensor;
import service.Impl.AlarmSystem;
import service.Impl.DisplayDevice;
import service.Observer;

public class ObserverPatternDemo {
    public static void main(String[] args) {
        // 创建主题和观察者
        TemperatureSensor sensor = new TemperatureSensor();
        Observer display = new DisplayDevice();
        Observer alarm = new AlarmSystem();

        // 注册观察者：如果没注册，那就不会通知
        sensor.addObserver(display);
        sensor.addObserver(alarm);

        // 改变主题的状态
        sensor.setTemperature(45);
        System.out.println("----------------------------------");
        sensor.setTemperature(28);
    }
}
